// pages/my_evaluate/my_evaluate.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jobComments: null,
    jobCommentsMore: {page:1},

    companyComments: null,
    companyCommentsMore: {page:1},

    shopComments: null,
    shopCommentsMore: {page:1},

    page:1,
    list: null,

    info: [],


    nav: 0
  },
  nav: function (e) {
    this.setData({
      nav: e.currentTarget.dataset.index
    });
    if(this.data.nav==1 && this.data.companyComments===null) {
      this.fetchCompanyComments();
    }
    if(this.data.nav==2 && this.data.shopComments===null) {
      this.fetchShopComments();
    }
    if(this.data.nav==3 && this.data.list===null) {
      this.setData({list: []});
      this.get_discover_comment_list();
    }
  },

  // 获取发现评论列表
  get_discover_comment_list(){
    var that = this;
    var page = that.data.page;
    var list = that.data.list;
    core.post({
      url: '/discover/get_discover_comment_list',
      data: { page:page },
      success(res) {
        if (res.code == 1) {
          for(var i=0; i<res.data.length; i++){
            list.push(res.data[i])
          }
          that.setData({ list: list });
        }
      }
    })
  },
  // 进入详情页
  post_detail: function (e) {
    console.log(e)
    var post_id = e.currentTarget.dataset.post_id;
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/post_detail/post_detail?post_id=' + post_id + '&type=' + type
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // this.get_discover_comment_list();
    this.fetchJobComments();
    
  },
  onReachBottom: function () {
    var nav = this.data.nav;
    if(nav == 3){
      var page = this.data.page;
      page++;
      this.setData({ page:page })
      this.get_discover_comment_list()
    }
  },

  fetchJobComments() {
    util.fetch(this, 'xilujob.interview_comment/my_comment', {}, 'jobCommentsMore', 'jobComments', 'data', 'unique');
  },
  fetchCompanyComments() {
    util.fetch(this, 'xilujob.company_comment/my_comment', {}, 'companyCommentsMore', 'companyComments', 'company_comments', 'unique');
  },
  fetchShopComments() {
    util.fetch(this, 'shop_comment/my_post', {}, 'shopCommentsMore', 'shopComments', 'shop_comments', 'unique');
    
  }

});
